package data;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

import snap.Snap;

public class Tree {
	private ConcurrentHashMap<String, Node> data = new ConcurrentHashMap<String, Node>();

	public Tree() {
		Node node = new Node("/root", "root", null);
		this.create(node);
	}

	public void create(Node node) {
		data.put(node.getPath(), node);
	}

	public void delete(String path) {
		data.remove(path);
	}

	public Node get(String path) {
		return data.get(path);
	}

	public void snap() throws FileNotFoundException, IOException {
		Snap.write(data);
	}

	public void init() throws FileNotFoundException, IOException, ClassNotFoundException {
		data = Snap.read();
	}
}